home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11807 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  47 lines

  1. Newsgroups: comp.lang.c++
  2. Path: iiasa.ac.at!marek
  3. From: marek@iiasa.ac.at (Marek  MAKOWSKI)
  4. Subject: Re: error: undef. but decl. template as member
  5. Message-ID: <1996Mar16.085325.25956@iiasa.ac.at>
  6. Organization: IIASA, Laxenburg, Austria
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. References: <Do6owF.LKo@news.uwindsor.ca>
  9. Date: Sat, 16 Mar 1996 08:53:25 GMT
  10.  
  11. Saed Aryan,13325,1100,g (saed@engn.uwindsor.ca) wrote:
  12. : Hi all,
  13.  
  14. : I am curious to know:
  15.  
  16. : --- Why is it not sufficient to declare a template in order to be able to
  17. :     use it as a member of a class, and then to define the template class later.
  18.  
  19. : I would like to know whether this is compiler specific or whether it's a C++
  20. : template flaw, since the error does not make logical sense to me. 
  21. : The code snippet below shows the problem. If you succeed in compiling this code
  22. : errorless, or if you have an explanataion, I'd be glad to know!
  23.  
  24. : Thanks a lot,
  25. : Aryan.
  26.  
  27. : //----cut here
  28. : template <class T> class A1{};        // A1 declared and defined
  29. : template <class T> class A2;        // A2 just declared
  30.  
  31. : class B1 {private: A1<int> a1;};// okay, A1 with template is defined
  32. // and therefore size of A1<int> is known at this point.
  33. : class B2 {private: A2<int> a2;};// error: field `a2' has incomplete type 
  34. // size of A2<int> is unknown at this point.
  35. // If there is a reason (often it is) to keep it uknown then you can use:
  36.   class B2 {private: A2<int> *a2;};// should be OK
  37.  
  38. Good luck,
  39. Marek
  40.  
  41.  
  42. -- 
  43.                   Marek Makowski  | Email: marek@iiasa.ac.at
  44.          International Institute  | Phone: (+43-2236) 807.561
  45.     for Applied Systems Analysis  | Fax:   (+43-2236) 71.313
  46.        A-2361 Laxenburg, Austria  | Web: http://www.iiasa.ac.at
  47.